﻿using System;
using System.ComponentModel;
using System.Drawing;
using System.Windows.Markup;

namespace RSkor.Common.WinForms
{
    [MarkupExtensionReturnType(typeof(Font))]
    public class FontExtension : BaseMarkupExtension
    {
        // Summary:
        //     Gets a value that indicates whether this System.Drawing.Font is bold.
        //
        // Returns:
        //     true if this System.Drawing.Font is bold; otherwise, false.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool Bold { get; set; }

        //
        // Summary:
        //     Gets or sets the System.Drawing.FontFamily associated with this System.Drawing.Font.
        //
        // Returns:
        //     The System.Drawing.FontFamily associated with this System.Drawing.Font.
        [Browsable(false)]
        public string FontFamily { get; set; }

        //
        // Summary:
        //     Gets or sets a byte value that specifies the GDI character set that this System.Drawing.Font
        //     uses.
        //
        // Returns:
        //     A byte value that specifies the GDI character set that this System.Drawing.Font
        //     uses.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public byte GdiCharSet { get; set; }

        //
        // Summary:
        //     Gets or sets a Boolean value that indicates whether this System.Drawing.Font is derived
        //     from a GDI vertical font.
        //
        // Returns:
        //     true if this System.Drawing.Font is derived from a GDI vertical font; otherwise,
        //     false.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool GdiVerticalFont { get; set; }

        ////
        //// Summary:
        ////     Gets a value indicating whether the font is a member of System.Drawing.SystemFonts.
        ////
        //// Returns:
        ////     true if the font is a member of System.Drawing.SystemFonts; otherwise, false.
        ////     The default is false.
        //[Browsable(false)]
        //public bool IsSystemFont { get; }
        //
        // Summary:
        //     Gets a value that indicates whether this System.Drawing.Font is italic.
        //
        // Returns:
        //     true if this System.Drawing.Font is italic; otherwise, false.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool Italic { get; set; }

        //
        // Summary:
        //     Gets the em-size of this System.Drawing.Font measured in the units specified
        //     by the System.Drawing.Font.Unit property.
        //
        // Returns:
        //     The em-size of this System.Drawing.Font.
        public float Size { get; set; }

        ////
        //// Summary:
        ////     Gets the em-size, in points, of this System.Drawing.Font.
        ////
        //// Returns:
        ////     The em-size, in points, of this System.Drawing.Font.
        //[Browsable(false)]
        //public float SizeInPoints { get; set; }
        //
        // Summary:
        //     Gets a value that indicates whether this System.Drawing.Font specifies a
        //     horizontal line through the font.
        //
        // Returns:
        //     true if this System.Drawing.Font has a horizontal line through it; otherwise,
        //     false.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool Strikeout { get; set; }

        //
        // Summary:
        //     Gets style information for this System.Drawing.Font.
        //
        // Returns:
        //     A System.Drawing.FontStyle enumeration that contains style information for
        //     this System.Drawing.Font.
        [Browsable(false)]
        public FontStyle Style
        {
            get
            {
                FontStyle result = Italic ? FontStyle.Italic : FontStyle.Regular;
                if (Underline)
                    result |= FontStyle.Underline;
                if (Bold)
                    result |= FontStyle.Bold;
                if (Strikeout)
                    result |= FontStyle.Strikeout;
                return result;
            }
        }

        //
        // Summary:
        //     Gets a value that indicates whether this System.Drawing.Font is underlined.
        //
        // Returns:
        //     true if this System.Drawing.Font is underlined; otherwise, false.
        [DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
        public bool Underline { get; set; }
        //
        // Summary:
        //     Gets the unit of measure for this System.Drawing.Font.
        //
        // Returns:
        //     A System.Drawing.GraphicsUnit that represents the unit of measure for this
        //     System.Drawing.Font.
        [TypeConverter(typeof(FontConverter.FontUnitConverter))]
        public GraphicsUnit Unit { get; set; }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="serviceProvider"></param>
        /// <returns></returns>
        public override object ProvideValue(IServiceProvider serviceProvider)
        {
            Font result = new Font(this.FontFamily, this.Size, this.Style,
                this.Unit, this.GdiCharSet, this.GdiVerticalFont);
            return result;
        }
    }
}
